package com.lottery.obtainData.AchieveDataImpl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lottery.dto.*;
import com.lottery.entity.Account;
import com.lottery.entity.Lottery;
import com.lottery.entity.LotteryExchange;
import com.lottery.entity.User;
import com.lottery.initData.InitData;
import com.lottery.obtainData.AchieveData;
import com.lottery.obtainData.ObtainDataUtils;
import com.lottery.obtainData.SscYesWinningFactory.SscWinResult;
import com.lottery.utils.*;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class SscAchieveDataImpl extends AchieveData {
    private MessageTubes messageTubes = MessageTubes.getInstance();


    // 中奖信息标志key
    @Value("${SSCFLG}")
    private String FLG;
    // 当前开奖的期号
    @Value("${SSCEXPECT}")
    private String EXPECT;
    // 当前开奖的号码
    @Value("${SSCOPENCODE}")
    private String OPENCODE;
    // 当前开奖的时间
    @Value("${SSCOPENDATE}")
    private String OPENDATE;
    // 下一次开奖的时间
    @Value("${SSCNEXTTIME}")
    private String NEXTTIME;
    // 下一次开奖的期号
    @Value("${SSCNEXTEXPECT}")
    private String NEXTEXPECT;

    // 开奖接口
    @Value("${SSCLOTTERYINTERFACE}")
    private String LOTTERYINTERFACE;

    // 开始下注
    @Value("${OPENNUM}")
    private String OPENNUM;
    // 开奖信息前缀
    @Value("${BEFOR}")
    private String BEFOR;
    // 开奖信息后缀
    @Value("${AFTER}")
    private String AFTER;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    protected void insertPromptNotice(WinProperty ssc) {
        String expect = ssc.getExpect();
        String opencode =ssc.getOpencode();
        String rule = ssc.getRule();
        msgNoticeService.insertPromptNotice(
                BEFOR + expect + OPENNUM + opencode.replace(",", " ") + " " + rule + AFTER, lotteyType);
    }

    @Override
    protected String StartAction(){
        String curFullPeoriod = ObtainDataUtils.getFullPeriod(new Date());
        //**********缺漏期数不开待修改
        //JudgmentCheck(curFullPeoriod);
        // 最近开奖的信息
        Lottery selectLottery = lotteryDao.selectLotteryByExpect(curFullPeoriod);
        if (selectLottery != null) {
            // 当前开奖期号,当前开奖号码,当前开奖时间,
            jedisClient.set(EXPECT, selectLottery.getExpect());
            jedisClient.set(OPENCODE, selectLottery.getOpencode());
        }
        // 下一期开奖时间,下一期开奖期号
        String nextPeoriod = ObtainDataUtils.getNextExpect(curFullPeoriod);
        Date nextPeoriodDate = obtainTime(nextPeoriod);
        String nextDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(nextPeoriodDate);
        jedisClient.set(NEXTEXPECT, nextPeoriod);
        jedisClient.set(NEXTTIME, nextDate);
        return nextDate;
    }

    @Override
    protected boolean judgeWinBet(WinProperty ssc) {
        boolean flag = false;
        // 获得接口数据
        String url = LOTTERYINTERFACE;
        String httpRequest = ObtainDataUtils.obtainData(url);
        if (httpRequest == null) {
            logger.info("接口返回null");
            flag = true;
        }

        JSONObject parseObject = ObtainDataUtils.stringToJson(httpRequest);
        if (parseObject == null) {
            logger.info("接口获取为 null:{}", httpRequest);
            flag = true;
        }
        JSONObject nowExpectInfo = JSON.parseObject(String.valueOf(parseObject.getJSONArray("data").get(0)));
        String expect = nowExpectInfo.getString("expect");
        ssc.setNowExpectInfo(nowExpectInfo);
        ssc.setExpect(expect);
        // 从redis中查询上一期的开奖期号
        String expectRedis = jedisClient.get(EXPECT);
        ssc.setExpectRedis(expectRedis);

        // 如果本次获取的开奖信息和上次相同,就结束本次循环
        if (expect.equals(expectRedis)) {
           // logger.info("本次获取的开奖期号和redis相同:{}", expectRedis);
            flag = true;
        }
        // 查看数据库中是否有该期号的数据,如果有,就结束本次循环
        Lottery selectLotteryByExpect = lotteryDao.selectLotteryByExpect(expect);
        if (selectLotteryByExpect != null) {
           // logger.info("数据库已有该记录,结束本次循环");
            flag = true;
        }
        return flag;
    }

    @Override
    protected boolean getWinInfomation(WinProperty ssc) {
        boolean flag = false;
        // 如果本次获取的开奖信息和上次不同,就将本次的开奖信息存入数据库并跟新redis中的内容
        JSONObject nowExpectInfo = ssc.getNowExpectInfo();
        String opencode = nowExpectInfo.getString("opencode");
        ssc.setOpencode(opencode);
        Date opentime = nowExpectInfo.getDate("opentime");

        String expect = ssc.getExpect();

        //得到开奖结果
        SscWinResult sscc = new SscWinResult();
        sscc.init(opencode);

        String result = getLotteyWinResult(opencode);

        // 插入数据库
        Boolean insertLottery = insertLottery(expect, Integer.parseInt(expect.substring(8, 11)), opencode,
                opentime,result);
        if (!insertLottery) {
            logger.error("插入数据库出错");
            flag = true;
        }

        // 当前开奖期号,当前开奖号码,当前开奖时间,
        jedisClient.set(EXPECT, expect);
        jedisClient.set(OPENCODE, opencode);
        jedisClient.set(OPENDATE, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(opentime));

        // 下一期开奖时间,下一期开奖期号
        String nextExpect = ObtainDataUtils.getNextExpect(expect);
        ssc.setNextExpect(nextExpect);
        Date nextTimeDate = obtainTime(nextExpect);
        String nextTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(nextTimeDate);
        ssc.setNextTime(nextTime);
        jedisClient.set(NEXTEXPECT, nextExpect);
        jedisClient.set(NEXTTIME, nextTime);
        //logger.info("1号接口下次开奖的时间+开奖的期号:{}", nextTime + " + " + nextExpect);

        // 分割字符串
        String[] str = opencode.split(",");
        int amount = Integer.parseInt(str[0]) + Integer.parseInt(str[1]) + Integer.parseInt(str[2])
                + Integer.parseInt(str[3]) + Integer.parseInt(str[4]);
        String rule = "";
        if (amount >= 23 && amount % 2 != 0) {
            rule = "大单";
        } else if (amount < 23 && amount % 2 != 0) {
            rule = "小单";
        } else if (amount >= 23 && amount % 2 == 0) {
            rule = "大双";
        } else if (amount < 23 && amount % 2 == 0) {
            rule = "小双";
        }
        ssc.setRule(rule);
        //调用长龙的处理方法
        dealWithChanglong();
        return flag;
    }

    private String getLotteyWinResult(String opencode){
        String result = "";
        Integer amout = 0;
        String[] split = opencode.split(",");
        for(String ss:split){
            amout += Integer.parseInt(ss);
        }
        result += amout+",";
        Map<Integer, List<String>> sscWinresultMap = InitData.SSC_WINRESULT_MAP;
        //拼接特码的部分开奖结果
        List<String> strings = sscWinresultMap.get(6);
        int  i = 0;
        for(String ss :strings){
            if(ss.length() == 1){
                result +=ss+",";
            }else if(ss.length() == 3){
                result +=ss.substring(2)+",";
            }else{
                continue;
            }
        }
        result=result.substring(0,(result.length()-1));
        result +="&&";
        //拼接龙虎的开奖结果
        List<String> longHu = sscWinresultMap.get(8);
        result += longHu.get(0)+",";
        //拼接三球组的开奖结果
        List<String> sanqiu = sscWinresultMap.get(9);
        Map<Integer,String> map = new HashMap<>();
        for(String ss : sanqiu){
            if(ss.contains("前")){
                map.put(1,ss.substring(2));
            }else if(ss.contains("中")){
                map.put(2,ss.substring(2));
            }else{
                map.put(3,ss.substring(2));
            }
        }
        result +=map.get(1)+","+map.get(2)+","+map.get(3);
        return result;
    }

    @Override
    protected void robotBet(WinProperty ssc) {
        String nextTime = ssc.getNextTime();
        String nextExpect = ssc.getNextExpect();
        try {
            PlayWayThread playWayThread = new PlayWayThread();
            playWayThread.setNextTime(nextTime);
            playWayThread.setNextExpect(nextExpect);
            playWayThread.setLotteyType(lotteyType);
            playWayThread.start();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("create thread error ", e);
        }

    }

    @Override
    protected void selectWinningResultsService(WinProperty ssc) {
//        String expect = ssc.getExpect();
//        // 根据期号查询
//        List<WinningResultsDto> winningResultsList = winningResultsDao.selectWinningResultsByExpect(expect);
//        for (WinningResultsDto winningResultsDto : winningResultsList) {
//
//            // 获取中奖状态state和user_id和下注规则bettingrule
//            int state = winningResultsDto.getState();
//            String userId = String.valueOf(winningResultsDto.getUserId());
//            String bettingrule = winningResultsDto.getBettingrule() + " " + winningResultsDto.getBettingMoney();
//            double winningamount = winningResultsDto.getWinningamount();
//
//            // 账户余额
//            Account selectAccountByUserId = accountDao.selectAccountByUserId(winningResultsDto.getUserId());
//            double accountFunds = selectAccountByUserId.getAccountFunds();
//
//            // 下注人信息
//            User selectId = userDao.selectId(winningResultsDto.getUserId());
//            String allBetNotice = "";
//
//            String hget = jedisClient.hget(FLG, userId);
//            if (hget == null) {
//                List<InfoStateDto> list = new ArrayList<>();
//                InfoStateDto info = new InfoStateDto();
//                String msString = "";
//                if (state == 0) {
//                    msString = "您于" + expect + "期投注的:" + bettingrule + " 未中奖.账户余额为:"
//                            + String.format("%.2f", accountFunds) + "彩钻";
//                    info.setState(0);
//                    info.setMessage(msString);
//                } else {
//                    msString = "您于" + expect + "期投注的:" + bettingrule + " 中奖啦!中奖金额为:"
//                            + String.format("%.2f", winningamount) + "彩钻,账户余额为:" + String.format("%.2f", accountFunds)
//                            + "彩钻";
//                    allBetNotice = "在" + expect + "期投注的:" + bettingrule + " 中奖啦!中奖金额为:"
//                            + String.format("%.2f", winningamount) + "彩钻,账户余额为:" + String.format("%.2f", accountFunds)
//                            + "彩钻";
//                    info.setState(1);
//                    info.setMessage(msString);
//                }
//                list.add(info);
//                String objectToJson = JsonUtils.objectToJson(list);
//                jedisClient.hset(FLG, userId, objectToJson);
//                logger.debug("set2 redis {} -- {}--{}", FLG, userId, objectToJson);
//            } else {
//                List<InfoStateDto> jsonToList = JsonUtils.jsonToList(hget, InfoStateDto.class);
//                InfoStateDto info = new InfoStateDto();
//                String msString = "";
//                if (state == 0) {
//                    msString = "您于" + expect + "期投注的:" + bettingrule + " 未中奖.账户余额为:"
//                            + String.format("%.2f", accountFunds) + "彩钻";
//                    info.setState(0);
//                    info.setMessage(msString);
//                } else {
//                    msString = "您于" + expect + "期投注的:" + bettingrule + " 中奖啦!中奖金额为:"
//                            + String.format("%.2f", winningamount) + "彩钻,账户余额为:" + String.format("%.2f", accountFunds)
//                            + "彩钻";
//                    allBetNotice = "在" + expect + "期投注的:" + bettingrule + " 中奖啦!中奖金额为:"
//                            + String.format("%.2f", winningamount) + "彩钻,账户余额为:" + String.format("%.2f", accountFunds)
//                            + "彩钻";
//                    info.setState(1);
//                    info.setMessage(msString);
//                }
//                jsonToList.add(info);
//                String objectToJson = JsonUtils.objectToJson(jsonToList);
//                jedisClient.hset(FLG, userId, objectToJson);
//                logger.debug("set3 redis {} -- {}--{}", FLG, userId, objectToJson);
//            }
//            if (!allBetNotice.equals("")) {
//                msgNoticeService.insertBetNotice(winningResultsDto.getUserId(), allBetNotice, lotteyType, agencyMark, result);
//            }
//        }
//
//        // 游客开奖信息
//        MessageTube messageTube = messageTubes.getSscBetMessageTube();
//        for (Map.Entry<Integer, ArrayList<LotteryExchange>> entity : TouristData.touristWin.entrySet()) {
//            // MessageTube messageTube = MessageTube.getInstance();
//            String userId = entity.getKey() + "";
//            for (LotteryExchange one : entity.getValue()) {
//                String allBetNotice = "";
//                String hget = jedisClient.hget(FLG, entity.getKey() + "");
//                double accountFunds = Double.parseDouble(jedisClient.hget(userId, "amount"));
//                String userName = TouristData.touristInfo.get(entity.getKey()).getTouristName();
//                if (hget == null) {
//                    List<InfoStateDto> list = new ArrayList<>();
//                    InfoStateDto info = new InfoStateDto();
//                    String msString = "";
//                    String betRule = one.getBettingrule() + " " + one.getBettinginfoId() + ".0";
//                    if (one.getWinningamount() == 0) {
//                        msString = "您于" + expect + "期投注的:" + betRule + " 未中奖.账户余额为:"
//                                + String.format("%.2f", accountFunds) + "彩钻";
//                        info.setState(0);
//                        info.setMessage(msString);
//                    } else {
//                        msString = "您于" + expect + "期投注的:" + betRule + " 中奖啦!中奖金额为:"
//                                + String.format("%.2f", one.getWinningamount()) + "彩钻,账户余额为:"
//                                + String.format("%.2f", accountFunds) + "彩钻";
//                        allBetNotice = "在" + expect + "期投注的:" + betRule + " 中奖啦!中奖金额为:"
//                                + String.format("%.2f", one.getWinningamount()) + "彩钻,账户余额为:"
//                                + String.format("%.2f", accountFunds) + "彩钻";
//                        info.setState(1);
//                        info.setMessage(msString);
//                    }
//
//                    list.add(info);
//                    String objectToJson = JsonUtils.objectToJson(list);
//                    jedisClient.hset(FLG, userId, objectToJson);
//                    logger.debug("set2 redis {} -- {}--{}", FLG, userId, objectToJson);
//                } else {
//                    List<InfoStateDto> jsonToList = JsonUtils.jsonToList(hget, InfoStateDto.class);
//                    InfoStateDto info = new InfoStateDto();
//                    String msString = "";
//                    String betRule = one.getBettingrule() + " " + one.getBettinginfoId();
//                    if (one.getWinningamount() == 0) {
//                        msString = "您于" + expect + "期投注的:" + betRule + " 未中奖.账户余额为:"
//                                + String.format("%.2f", accountFunds) + "彩钻";
//                        info.setState(0);
//                        info.setMessage(msString);
//                    } else {
//                        msString = "您于" + expect + "期投注的:" + betRule + " 中奖啦!中奖金额为:"
//                                + String.format("%.2f", one.getWinningamount()) + "彩钻,账户余额为:"
//                                + String.format("%.2f", accountFunds) + "彩钻";
//                        allBetNotice = "在" + expect + "期投注的:" + betRule + " 中奖啦!中奖金额为:"
//                                + String.format("%.2f", one.getWinningamount()) + "彩钻,账户余额为:"
//                                + String.format("%.2f", accountFunds) + "彩钻";
//                        info.setState(1);
//                        info.setMessage(msString);
//                    }
//
//                    jsonToList.add(info);
//                    String objectToJson = JsonUtils.objectToJson(jsonToList);
//                    jedisClient.hset(FLG, userId, objectToJson);
//                    logger.debug("set3 redis {} -- {}--{}", FLG, userId, objectToJson);
//                }
//                if (!allBetNotice.equals("")) {
//                    String body = userId + "::" + userName + "::" + 0 + "::" + allBetNotice;
//                    Message message = new Message();
//                    message.setMessageBody(body);
//                    message.setType("0");
//                    message.setTimestamp(new Date().getTime());
//                    int push = messageTube.push(message);
//                    logger.debug("return index={}, {},{},{}", messageTube.getHashCode(), push, message.getType(), body);
//                }
//            }
//        }
//
//        logger.debug("****robot :: show win infomation start***************");
//
//        // 显示内存中的中奖信息
//        // 机器人
//        for (Map.Entry<Integer, ArrayList<LotteryExchange>> entity : RobotParams.robotSscWin.entrySet()) {
//            String userId = entity.getKey() + "";
//            for (LotteryExchange one : entity.getValue()) {
//                if (one.getWinningamount() == 0) {
//                    continue;
//                }
//                String allBetNotice = "";
//
//                if (!RobotParams.robotinfoMap.containsKey(entity.getKey())) {
//                    continue;
//                }
//                String userName = RobotParams.robotinfoMap.get(entity.getKey()).getRobotName();
//
//                int times = RandCodeUtil.getRandNum(3, 9);
//                String robotBetInfo = AchieveDataUtil.robotDivision(one.getBettingrule()) + ".0";
//                allBetNotice = "在" + expect + "期投注的:" + robotBetInfo + " 中奖啦!中奖金额为:"
//                        + String.format("%.2f", one.getWinningamount()) + "彩钻,账户余额为:"
//                        + String.format("%.2f", one.getWinningamount() * times) + "彩钻";
//
//                logger.debug("****robot sscxianshi:{}", allBetNotice);
//
//                if (!allBetNotice.equals("")) {
//                    String body = userId + "::" + userName + "::" + 0 + "::" + allBetNotice;
//                    Message message = new Message();
//                    message.setMessageBody(body);
//                    message.setType("0");
//                    message.setTimestamp(new Date().getTime());
//                    int push = messageTube.push(message);
//                    logger.debug("robot return index={}, {},{},{}", messageTube.getHashCode(), push, message.getType(),
//                            body);
//                }
//            }
//        }
    }

    @Override
    protected void YesWinningFactory(WinProperty ssc) {
        lotteryDrawService.sscYesWinningFactory(ssc.getOpencode(),ssc.getExpect(),lotteyType);
    }

    public void JudgmentCheck(String expect) {
        String substring = expect.substring(0, 8);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        Date parse = null;
        try {
            parse = simpleDateFormat.parse(substring);
        } catch (ParseException e) {
            logger.info("1号接口日期转换异常:{}", "转换昨天日期异常");
        }
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(parse);
        calendar.add(Calendar.DATE, -1);// 把日期往后增加一天.整数往后推,负数往前移动
        parse = calendar.getTime();
        String yesterday = simpleDateFormat.format(parse).substring(0, 8) + "120";
        checkOut(yesterday);
        checkOut(expect);

    }

    // 校验数据
    public void checkOut(String expect) {
        logger.info("expect={}", expect);
        List<String> todayExpect = lotteryDao.selectExpectByExpect(expect.substring(0, 8));
        logger.info("todayExpect={}", todayExpect);

        ArrayList<String> lackList = new ArrayList<>();
        // 如果查出来的list长度等于当前期号,则无缺漏
        if (todayExpect.size() == Integer.valueOf(expect.substring(8, 11))) {
            return;
        } else {
            // 有缺漏
            String substring = expect.substring(0, 8);
            // 获得当天所有开奖的期数
            for (int i = 1; i <= Long.valueOf(expect.substring(8, 11)); i++) {
                if (String.valueOf(i).length() == 1) {
                    lackList.add(substring + "00" + i);
                }
                if (String.valueOf(i).length() == 2) {
                    lackList.add(substring + "0" + i);
                }
                if (String.valueOf(i).length() == 3) {
                    lackList.add(substring + i);
                }
            }
            logger.info("当天所有开奖的期数:{}", lackList);
            // 获得缺漏的期数
            for (String string : todayExpect) {
                lackList.remove(string);
            }
            logger.info("缺漏的期数:{}", lackList);
            // 获得校验的模板
            Map<String, String> checkData = checkData(expect);

            // 对照模板补全缺漏的期数,并开奖
            for (String string : lackList) {
                String key = string.substring(8, 11);
                String opencode = checkData.get(key);
                Date opentime = obtainTime(string);
                SscWinResult ssc = new SscWinResult();
                ssc.init(opencode);
                String result = getLotteyWinResult(opencode);
                insertLottery(string, Integer.valueOf(key), opencode, opentime,result);
                /****** 时时彩待修改 ******************/
                lotteryDrawService.sscYesWinningFactory(opencode, string, 1);
            }
        }
    }


    // 开奖时间的获得
    public Date obtainTime(String expect) {
        // 开奖的时间
        String formatDate = expect.substring(0, 4) + "-" + expect.substring(4, 6) + "-" + expect.substring(6, 8);
        String formatMorning = formatDate + " 00:00:00";
        String formatForenoon = formatDate + " 10:00:00";
        String formatEvening = formatDate + " 22:00:00";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long timeMorning = 0;
        long timeForenoon = 0;
        long timeEvening = 0;
        long timeNow = 0;
        try {
            timeMorning = simpleDateFormat.parse(formatMorning).getTime();
            timeForenoon = simpleDateFormat.parse(formatForenoon).getTime();
            timeEvening = simpleDateFormat.parse(formatEvening).getTime();
        } catch (ParseException e) {
            logger.info("错误={}", "日期转换出错");
        }
        Long NextExpectNumber = Long.valueOf(expect.substring(8, 11));
        if (NextExpectNumber >= 1 && NextExpectNumber <= 23) {
            timeNow = timeMorning + 300000 * NextExpectNumber;
        }
        if (NextExpectNumber >= 24 && NextExpectNumber <= 96) {
            timeNow = timeForenoon + 600000 * (NextExpectNumber - 24);
        }
        if (NextExpectNumber >= 97 && NextExpectNumber <= 120) {
            timeNow = timeEvening + 300000 * (NextExpectNumber - 96);
        }
        Date date = new Date(timeNow);
        logger.info("开奖的时间={}", date);
        return date;
    }

    // 获取校验模板
    public Map<String, String> checkData(String substring) {
        Document doc = null;
        ArrayList<String> list = new ArrayList<>();
        ArrayList<String> copyList = new ArrayList<>();
        boolean flag = true;
        while (flag) {
            try {
                doc = Jsoup.connect("http://caipiao.163.com/award/cqssc/" + substring + ".html").get();
            } catch (IOException e) {
                e.printStackTrace();
                logger.info("错误信息={}", "拉取html页面出错");
            }
            list = new ArrayList<>();
            Elements trs = doc.select("table").select("tr");
            for (int i = 0; i < trs.size(); i++) {
                Elements tds = trs.get(i).select("td");
                for (int j = 0; j < tds.size(); j++) {
                    String text = tds.get(j).text();
                    if (isInteger(text.charAt(0) + "")) {
                        list.add(text);
                    }
                }
            }
            for (String s : list) {
                if (s.length() == 3 && Integer.valueOf(s) > Integer.valueOf(substring.substring(8, 11))) {
                } else {
                    copyList.add(s);
                }
            }
            if (copyList.size() % 2 == 1) {
                list.clear();
                copyList.clear();
                flag = true;
                continue;
            }

            break;
        }

        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < copyList.size(); i = i + 2) {
            map.put(copyList.get(i), copyList.get(i + 1).replace(" ", ","));
        }
        logger.info("map={}", map);
        return map;
    }
    // 判断是否为整数
    private static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("[0-9]+");
        Matcher matcher = pattern.matcher((CharSequence) str);
        return matcher.matches();
    }

    //得到长龙结果
    private static void dealWithChanglong(){
        InitData.SSC_SORT_CHANGLONG.clear();
        Map<Integer, List<String>> sscWinresultMap = InitData.SSC_WINRESULT_MAP;
        List<Changlong> list = InitData.SSC_STORE_CHANGLONG;
        //更新连期信息
        list.forEach((c)->{
            String k = c.getBetRule();
            int v = c.getContinueNumber();
            if(sscWinresultMap.get(4).contains(k) || sscWinresultMap.get(6).contains(k) || sscWinresultMap.get(8).contains(k)){
                v=v+1;
                c.setContinueNumber(v);
            }else{
                c.setContinueNumber(0);
            }
            InitData.SSC_SORT_CHANGLONG.add(new Changlong(k,v));
        });
        //长龙排序
        InitData.SSC_SORT_CHANGLONG.sort(new ChanglongComparator());
    }
}
